Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search entities in the correct namespace #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lucaswerkmeister
Copy link
Contributor

@lucaswerkmeister lucaswerkmeister commented Apr 21, 2017

Instead of assuming that all entities are in namespace 0 (which is only true in a Wikidata-like installation, but not in a default Wikibase installation, and even then only for items, not properties), take the actual namespace of the requested entity from an injected EntityNamespaceLookup.

Also, if we can’t find the entity, throw an exception instead of returning count 0: it’s better to fail the import than to duplicate statements.

Fixes #22.

@@ -14,13 +14,15 @@ public function __construct( LoadBalancer $loadBalancer ) {
}

public function getStatementCount( EntityId $entityId ) {
global $wgWBRepoSettings;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this extension depend on Wikibase Repo? Not seeing that in composer.json. Then again, there is no wikibase repo specific package (which makes depending on it all the more insane)

If it does not, then you presumably want to default in this code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m not sure I understand your concern. This extension already uses Wikibase classes (DataModel, Lib, and Repo) everywhere; surely it logically depends on Wikibase Repo, whether that’s encoded in the composer.json or not?

I guess a more object-oriented approach would be to pass an EntityNamespaceLookup to the PagePropsStatementCountLookup and call getEntityNamespaces() instead of looking at the settings, but that’s still a Wikibase class.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’ve changed it now to use WikibaseRepo::getEntityNamespaces() instead of accessing the global variable directly. The WikibaseRepo class is already used several times in the importer (and always with getDefaultInstance() as far as I can tell).

$db = $this->loadBalancer->getConnection( DB_MASTER );

$res = $db->selectRow(
array( 'page_props', 'page' ),
array( 'pp_value' ),
array(
'page_namespace' => 0,
'page_namespace' => array_values( $wikibaseRepo->getEntityNamespaces() ),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the pull request.

I think page_namespace here should be only the namespace for the given entity type (of the entityId) and not all entity namespaces.

we could get this from EntityNamespaceLookup.

also, EntityNamespaceLookup should be set in the constructor (ideally the dependency injected)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, that makes a lot of sense. I’ve uploaded a new version that uses an EntityNamespaceLookup.

@lucaswerkmeister lucaswerkmeister changed the title Search entities in all entity namespaces Search entities in the correct namespace Jan 10, 2018
Instead of assuming that all entities are in namespace 0 (which is only
true in a Wikidata-like installation, but not in a default Wikibase
installation, and even then only for items, not properties), take the
actual namespace of the requested entity from an injected
EntityNamespaceLookup.

Also, if we can’t find the entity, throw an exception instead of
returning count 0: it’s better to fail the import than to duplicate
statements.

Fixes filbertkm#22.
@D063520
Copy link

D063520 commented Jun 18, 2019

I encountered the same error, can we push this to master?

@lucaswerkmeister
Copy link
Contributor Author

The Wikidata/WikibaseImport fork has this and a few other fixes merged, try using that one.

@D063520
Copy link

D063520 commented Jun 18, 2019

Hi Lucas,

you worked quite a bit on this repository ... do you know if pull requests are merged at some point? If not, would you take pull request in your repository?

Salut
D063520

@JohnRDOrazio
Copy link

Before pulling this, I believe another change is needed for compatibility with Mediawiki 1.37.

WikibaseRepo::getDefaultInstance no longer exists, see https://phabricator.wikimedia.org/T280984 .

I am getting the following error when trying to import entities in Mediawiki 1.38:

Error: Call to undefined method Wikibase\Repo\WikibaseRepo::getDefaultInstance()
Backtrace:
from /var/www/.../w/extensions/WikibaseImport/maintenance/importEntities.php(112)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Importing existing entities re-adds statements
5 participants